#include<iostream>
#include<cstdio>
using namespace std;
/*
20
1 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0
*/
int m,a[200011],ah[200011];
int ans[6001][4101],ansi[5001],kuai[5001][2],ki=1,ks=1,hh=0;
int main()
{
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	cin>>m;
	for(int i=1;i<=m;i++) scanf("%d",&a[i]);
	kuai[ki][0]=ks;
	kuai[ki][1]=1;
	ah[1]=1;
	ans[ah[1]][++ansi[ah[1]]]=1;
	for(int i=2;i<=m;i++)
	{
		if(a[i]!=a[i-1])
		{
			ah[i]=1;
			ans[ah[i]][++ansi[ah[i]]]=i;
			kuai[ki][0]=ks;
			kuai[ki++][1]=i-1;
			ks=1;
		}
		else
		{
			ks++;
			bool f=true;
			if(ks<=kuai[ki-1][0]||ki==1)
			{
				ah[i]=ah[i-1]+1;
				ans[ah[i]][++ansi[ah[i]]]=i;
				 
			}
			else
			{
				for(int j=ki-1;j>=1;j--)
				{
					if(ks<=kuai[j][0]&&a[i]!=a[kuai[j][1]]&&f)
					{
						f=false;
						ah[i]=ah[i-1]+1;
						ans[ah[i]][++ansi[ah[i]]]=i;
					}
					else if(ks<=kuai[j][0]&&a[i]==a[kuai[j][1]]&&f)
					{
						f=false;
						ah[i]=ah[kuai[j][1]]+(ks-1);
						ans[ah[i]][++ansi[ah[i]]]=i;
					}
				}
				if(f)
				{
					ah[i]=ah[i-1]+1;
					ans[ah[i]][++ansi[ah[i]]]=i;
				}
			}
			kuai[ki][1]=i;
			kuai[ki][0]=ks;
		}
		hh=max(hh,ah[i]);
	}
	for(int i=1;i<=hh;i++)
	{
		for(int j=1;j<=ansi[i];j++)
		{
			printf("%d ",ans[i][j]);
		}
		cout<<endl;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
